{extend name="common/head"/}
	<link rel="stylesheet" href="{__ADMIN__}/js/jquery-tagsinput/jquery.tagsinput.min.css">
	<link href="{__ADMIN__}/css/style.min.css" rel="stylesheet">
{block name="body"}
<div class="container-fluid p-t-15">

	<div class="row">
		<div class="col-lg-12">
			<div class="card">
				<div class="card-body">

					<form onsubmit="return false" action="#!" method="post" class="row" id="form1">
						<input type="hidden" name="id" id="id" value="{$id}">
						<div class="form-group col-md-12">
							<label for="title">SMTP地址</label>
							<input type="text" class="form-control" id="smtp" name="smtp" {notempty name="$config.smtp"} value="{$config.smtp}" {/notempty} placeholder="请输入SMTP服务器地址" />
							<span style="color:#999; font-size:12px;">如：QQ邮箱的SMTP服务器地址是smtp.qq.com，163邮箱的SMTP服务器地址是smtp.163.com</span>
						</div>
						<div class="form-group col-md-12">
							<label for="title">协议端口号</label>
							<input type="text" class="form-control" id="smtp_port" name="smtp_port" {notempty name="$config.smtp_port"} value="{$config.smtp_port}" {/notempty} placeholder="请输入端口" />
							<span style="color:#999; font-size:12px;">如：QQ邮箱的ssl协议方式端口号是465/587，163邮箱的ssl协议方式端口号是465/994</span>
						</div>
						<div class="form-group col-md-12">
							<label for="title">邮箱账户</label>
							<input type="text" class="form-control" id="smtp_user" name="smtp_user" {notempty name="$config.smtp_user"} value="{$config.smtp_user}" {/notempty} placeholder="请输入邮箱用户名" />
							<span style="color:#999; font-size:12px;">如：mykc@qq.com</span>
						</div>
						<div class="form-group col-md-12">
							<label for="title">邮箱密码</label>
							<input type="password" class="form-control" id="smtp_pwd" name="smtp_pwd" {notempty name="$config.smtp_pwd"} value="{$config.smtp_pwd}" {/notempty} placeholder="请输入邮箱密码" />
							<span style="color:#999; font-size:12px;">不一定是登录密码，如QQ邮箱的是第三方授权登录码，要自己去开启，在邮箱的设置->账户->POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务</span>
						</div>
						<div class="form-group col-md-12">
							<label for="title">发送人</label>
							<input type="text" class="form-control" id="from" name="from" {notempty name="$config.from"} value="{$config.from}" {/notempty} placeholder="请输入要显示的发送者" />
							<span style="color:#999; font-size:12px;">用于展示给发送方，如：梦亚admin系统管理员</span>
						</div>
						<div class="form-group col-md-12">
							<label for="title">显示的邮箱</label>
							<input type="text" class="form-control" id="email" name="email" {notempty name="$config.email"} value="{$config.email}" {/notempty} placeholder="请输入要显示的发送者邮箱" />
							<span style="color:#999;font-size:12px;">可以不同于上面的账户，用于展示给发送方的邮箱，如：admin@dream-kc.com</span>
						</div>
						<div class="form-group col-md-12">
							<label for="title">邮件模板</label>
							<textarea id="testtextarea" name="template">{notempty name="$config.template"}{$config.template}{/notempty}</textarea>
						</div>
						<div class="form-group col-md-12">
							<button type="submit" class="btn btn-primary ajax-post" target-form="add-form" onclick="add()">确 定</button>
						</div>
					</form>

				</div>
			</div>
		</div>

	</div>

</div>
{/block}
{block name="script"}
{include file="common/footer" base="base" /}

<script src="{__ADMIN__}/js/tinymce/tinymce.min.js"></script>
<!--标签插件-->
<script src="{__ADMIN__}/js/jquery-tagsinput/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="{__ADMIN__}/js/main.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		tinymce.init({
			selector: '#testtextarea',
			language: 'zh_CN',
			directionality: 'ltl',
			browser_spellcheck: true,
			contextmenu: false,
			height: 480,
			plugins: [
				"advlist autolink lists link image charmap print preview anchor",
				"searchreplace visualblocks code fullscreen",
				"insertdatetime media table contextmenu paste imagetools wordcount",
				"code"
			],
			toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
			images_upload_url: '/admin/api/udupload', // 后端返回的json格式{ location : "/demo/image/1.jpg" }
		});
	});
	function add() {
		var cnt = tinyMCE.editors['testtextarea'].getContent();
		console.log(cnt);
		var id = $("#id").val();
		var smtp = $("#smtp").val();
		var smtp_port = $("#smtp_port").val();
		var smtp_user = $("#smtp_user").val();
		var smtp_pwd = $("#smtp_pwd").val();
		var from = $("#from").val();
		var email = $("#email").val();
		var template = cnt;
		var data = {
			id:id,
			smtp:smtp,
			smtp_port:smtp_port,
			smtp_user:smtp_user,
			smtp_pwd:smtp_pwd,
			from:from,
			email:email,
			template:template
		}
		$.ajax({
			//几个参数需要注意一下
			type: "POST",//方法类型
			dataType: "json",//预期服务器返回的数据类型
			url: "/admin/conf/conf_submit" ,//url
			data: data,
			success: function (res) {
				console.log(res);//打印服务端返回的数据(调试用)
				if (res.code === 0) {
					$.alert({
						title: '成功',
						icon: 'mdi mdi-alert',
						type: 'blue',
						content: res.msg,
						buttons: {
							okay: {
								text: '确认',
								btnClass: 'btn-blue',
								action: function() {
									location.reload();
								}
							}
						}
					});
					// setTimeout(function() {
					//     //	parent.document.location.reload();
					//     parent.document.location.href="{:url('/admin/index')}";
					// }, 1500);
				}else {
					$.alert({
						title: '错误',
						icon: 'mdi mdi-alert',
						type: 'red',
						content: res.msg,
						buttons: {
							okay: {
								text: '确认',
								btnClass: 'btn-blue',
								action: function() {
									//$('[alt="captcha"]').click();
								}
							}
						}
					});
				};
			},
			error : function() {
				$.alert({
					title: '警告',
					content: '请检查返回是否正常！',
					icon: 'mdi mdi-access-point-network-off',
					animation: 'scale',
					closeAnimation: 'scale',
					buttons: {
						okay: {
							text: '确认',
							btnClass: 'btn-blue'
						}
					}
				});
			}
		});
	}
</script>
{/block}
</body>
</html>